package com.example.myapplication

import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class TextView_MY : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_text_view)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val MyText = findViewById<TextView>(R.id.textView)

        MyText.text = "daffafafefafefffefefes"

        val btn = findViewById<View>(R.id.MyButton2)
        btn.setOnClickListener {
            Toast.makeText(this, "点我干啥??", Toast.LENGTH_SHORT).show()
        }


        val btn3 = findViewById<View>(R.id.MyButton3)
        btn3.setOnClickListener(this) // 设置监听器为当前 Activity

    }

    override fun onClick(v: View?) {
        // 需要通过 view.id 来区分不同的按钮。
        when (v?.id) {
            R.id.MyButton3 -> Toast.makeText(this, "不许点了???", Toast.LENGTH_SHORT).show()
        }
    }

    fun onclick(view: View) {
        Toast.makeText(this, "点我干啥?", Toast.LENGTH_SHORT).show()
    }


}